package com.yy.micro.magic.core.result.value;

import com.yy.micro.magic.core.result.name.NameStrategy;

import java.util.Map;


public class ValuePair {

    private String name;
    private  Object value;

    private Map<String,Object> parent;

    private NameStrategy strategy;

    public void setName(final String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setValue(final Object value) {
        this.value = value;
    }

    public Object getValue() {
        return value;
    }

    public void setStrategy(final NameStrategy strategy) {
        this.strategy = strategy;
    }

    public void updateParent(String name, Object value){
        if (null != parent){
            parent.put(getOutName(name),value);
        }
    }

    private String getOutName(String name){
        if (null != strategy){
            return strategy.format(name);
        }
        return name;
    }

    public void setParent(final Map<String, Object> parent) {
        this.parent = parent;
    }

    public Map<String, Object> getParent() {
        return parent;
    }

    public static ValuePair create(String key, Object value, final Map<String, Object> parent){
        ValuePair pair = new ValuePair();
        pair.name = key;
        pair.value = value;
        pair.setParent(parent);
        return pair;
    }
}
